package cn.sumpu.app.guoguojie.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.sumpu.app.guoguojie.dao.FriendDao;
import cn.sumpu.app.guoguojie.domain.Ext.MaybeFriend;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class FriendDaoImpl extends SqlSessionDaoSupport implements FriendDao {

	private final static Logger logger = LoggerFactory
			.getLogger(FriendDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> getSameBirthdayMemberList(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameBirthdayMemberList",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameBirthdayMemberList failure.", e);
			}
			throw new AppBusinessException("getSameBirthdayMemberList failure.", e);
		}
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> getSameAllFamilyInfo(String doorplate)
			throws AppBusinessException { 
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("doorplate", doorplate);
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllFamilyInfo",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllFamilyInfo failure.", e);
			}
			throw new AppBusinessException("getSameAllFamilyInfo failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> setSameTownReason(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.setSameTownReason",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("setSameTownReason failure.", e);
			}
			throw new AppBusinessException("setSameTownReason failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> setSameCountyReason(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.setSameCountyReason",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("setSameCountyReason failure.", e);
			}
			throw new AppBusinessException("setSameCountyReason failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> setSameCityReason(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.setSameCityReason",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("setSameCityReason failure.", e);
			}
			throw new AppBusinessException("setSameCityReason failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaybeFriend> setSameProvinceReason(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.setSameProvinceReason",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("setSameProvinceReason failure.", e);
			}
			throw new AppBusinessException("setSameProvinceReason failure.", e);
		}
	}


	@SuppressWarnings("unchecked")
	@Override
	public List<String> getSameAllDoorplateCity(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllDoorplateCity",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllDoorplateCity failure.", e);
			}
			throw new AppBusinessException("getSameAllDoorplateCity failure.", e);
		}
	}

	@Override
	public Integer getSameAllDoorplateCityCount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllDoorplateCityCount",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllDoorplateCityCount failure.", e);
			}
			throw new AppBusinessException("getSameAllDoorplateCityCount failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> getSameAllDoorplateProvince(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllDoorplateProvince",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllDoorplateProvince failure.", e);
			}
			throw new AppBusinessException("getSameAllDoorplateProvince failure.", e);
		}
	}

	@Override
	public Integer getSameAllDoorplateProvinceCount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllDoorplateProvinceCount",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllDoorplateProvinceCount failure.", e);
			}
			throw new AppBusinessException("getSameAllDoorplateProvinceCount failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> getSameAllDoorplateByCity(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return  getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.FriendMapper.getSameAllDoorplateByCity",map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSameAllDoorplateCity failure.", e);
			}
			throw new AppBusinessException("getSameAllDoorplateCity failure.", e);
		}
	}

}
